#include "qt_node/ros_proxy.hpp"

ROSProxy::ROSProxy(QObject *parent) : QObject(parent)
{
}

QString ROSProxy::receivedMessage() const
{
    return m_receivedMessage;
}

// 当子线程传来消息时，这个槽会被调用
void ROSProxy::onMessageReceived(const QString &msg)
{
    setReceivedMessage("Received from ROS: " + msg);
}

// QML调用这个函数
void ROSProxy::publishMessage(const QString &msg)
{
    // 发射信号，让子线程的ROS节点去工作
    emit doPublish(msg);
}

void ROSProxy::setReceivedMessage(const QString &msg)
{
    if (m_receivedMessage != msg) {
        m_receivedMessage = msg;
        emit receivedMessageChanged(); // 发射信号，通知QML更新
    }
}
